package com.wb.shuzu.lianxi;
import java.util.Arrays;
import java.util.Scanner;
/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月17日18:03
 */
public class Test1 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入一个数字:");
        int num = sc.nextInt();
        int[][] arr = new int[num][num];
        int val=1;
        int minX=0;
        int minY=0;
        int maxX=num-1;
        int maxY=num-1;
        while(minX<=maxX) {
            for (int i = minX; i <= maxX; i++) {
                arr[minY][i] = val++;
            }
            minY++;
            for (int i = minY; i <= maxY; i++) {
                arr[i][maxX]=val++;
            }
            maxX--;
            for (int i = maxX; i>= minX; i--) {
                arr[maxY][i]=val++;
            }maxY--;
            for (int i = maxX; i >minX; i--) {
                arr[i][minX]=val++;
            }minX++;
        }
        for(int i=0;i<arr.length;i++){
            for(int j=0;j<arr[i].length;j++){
                System.out.print(arr[i][j]+"\t");
            }
            System.out.println();
        }



/*
        for (int[] row : arr) {
            System.out.println(Arrays.toString(row));
        }*/

    }
}
